﻿@model PhoneBilling.Models.ExtensionMgtModel
<script type="text/javascript">
    function motion(groupID) {

        var str = checkedCustomer.join('!');

        window.location.href = "/Manage/ExtensionMotion?selectedItem=" + str + "&groupID=" + groupID;
    }
//    function c1() {
//        if ($(".c1").attr("checked") == "checked") {
//            $(".account").attr("checked", "checked");
//        }
//        else {
//            $(".account").removeAttr("checked");
//        }
//    }
    function del(id, name) {
        var r = confirm("确认删除分机：" + name + "吗？");
        if (r == true) {
            window.location.href = "/Manage/ExtensionDelete?groupID=" + id + "&id=" + name;
        }
        return false;
    }
    function delb(id) {
        var str = checkedCustomer.join('!');
        var phone = checkedCustomer.join(' ');
        if (phone == "")
            return;

        var r = confirm("确认删除下列分机吗？" + phone);
        if (r == true) {
            window.location.href = "/Manage/ExtensionBatchDelete?phone=" + str + "&groupID=" + id;
        }
        return false;
    }
//    function change() {
//        var grade = $(".grade").val();

//        if (grade != "") {
//            $(".ext").hide();
//            $(".E-" + grade).show();
//            $(".listCounts").text($(".E-" + grade).length);
//        }
//        else {
//            $(".ext").show();
//            $(".listCounts").text($(".ext").length);
//        }
//    }
</script>
<h3 class="title">
    @if(Model.IsDept)
    {
        <label>当前部门：</label>
    }
    else
    {
        <label>当前分组：</label>
    }
    @if (Model.Group != null)
    {
        @Html.DisplayFor(m => m.Group)
    }
    else
    {
        <label>
            (未分组分机)</label>
    }
    
        分机数：</label><label class="listCounts">@Model.ExtensionList.Count</label>
</h3>
@if (Model.Message != null)
{<h2>@Model.Message</h2>}
@*<script type="text/javascript">
    $(document).ready(function () {
        $("#btnNewExtension").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/ExtensionEdit?group=@Model.GroupID";
            }
        });
        $("#btnSort").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/ExtensionSort?id=@Model.GroupID";
            }
        });
        $("#btnDel").ligerButton(
        {
            click: function () {
                delb('@Model.GroupID');
            }
        });
        $("#btnMotion").ligerButton(
        {
            click: function () {
                motion('@Model.GroupID');
            }
        });
    });
    
</script>*@
<div class="system_toolbar">
    @if (!Model.IsDept)
    {
        <input type="button" id="btnNew" value="新增" />
        <input type="button" id="btnSort" value="排序" />
    }
    <input type="button" id="btnModify" value="修改" />
    <input type="button" id="btnMotion" value="迁移" />
    <input type="button" id="btnDelete" value="删除" />
</div>
@*@if (Model.Group != null)
{
    <p id="btn-create" class="box">
        <input type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
        <span></span><input type="button" id="btnNewExtension" value="新增分机" />
        @if (!Model.IsDept)
        {<span> </span><input type="button" id="btnSort" value="排序" />
        }
        <span></span><input type="button" id="btnDel" value="删除" />
        </a> <span>
        </span><input type="button" id="btnMotion" value="迁移" />
        </a></p>
}
else
{
    <p id="btn-create" class="box">
        <input type="checkbox" class="c1" onclick="c1()" checked="checked" /><label>全选</label>
        <span></span><input type="button" id="btnDel" value="删除" />
        </a> <span></span><input type="button" id="btnMotion" value="迁移" />
        </a></p>
}*@
@Html.HiddenFor(m => m.SelectItem, new { id = "SelectItem" })
@*<p id="btn-create" class="box">*@
    
        @*<span>
    </span>@Html.LabelFor(m => m.收费等级) @Html.DropDownListFor(m => m.收费等级, new SelectList(Model.GradeList, "ID", "Name"), new { style = "input-text", onchange = "change()", @class = "grade" })</p>*@
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.AppendLine(string.Format("var data={{Total:{0},", Model.ExtensionList.Count));
    sb.AppendLine("Rows:[");
    for (int i = 0; i < Model.ExtensionList.Count; i++)
    {
        var item = Model.ExtensionList[i];
        if (i == 0)
        {
            sb.Append("{");
        }
        else
        {
            sb.Append(",{");
        }
        sb.Append(string.Format("分机号码:'{0}',", item.分机号码));
        sb.Append(string.Format("分组:'{0}',", item.分组));
        sb.Append(string.Format("用户名:'{0}',", item.用户名));
        sb.Append(string.Format("收费等级:'{0}',", item.收费等级));
        sb.Append(string.Format("费率:'{0}',", item.费率));
        sb.Append(string.Format("收费话类:'{0}'", item.收费话类));
        sb.Append("}");
    }
    sb.AppendLine("]};");
    string data = sb.ToString();
}
<script type="text/javascript">
    @Html.Raw(data)
    
    var menu = $.ligerMenu({ top: 100, left: 100, width: 120, items:
            [
            { text: '新增', click: newclick },
            { line: true },
            { text: '修改', click: modifyclick },
            { line: true },
            { text: '删除', click: deleteclick }
            ]
        });
    var grid;
    $(function () {

        grid = $("#maingrid").ligerGrid({
            columns: [
                { display: '分机号码', name: '分机号码',width:100},
                { display: '分组', name: '分组',width:180},
                { display: '用户名', name: '用户名',width:140},
                { display: '收费等级', name: '收费等级',width:180},
                { display: '费率', name: '费率',width:120},
                { display: '收费话类', name: '收费话类',width:180}
                ],
                isScroll: false, data: data,pageSize:30,alternatingRow:true,checkbox: true, isChecked: f_isChecked,onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow,                onContextmenu: function (node, e) {
            actionNodeID = node;
            menu.show({ top: e.pageY, left: e.pageX });
            return false;
        }
        }
        );
        resetGridHeight(grid);
        $(window).resize(function () {
                resetGridHeight(grid);
            });
    });    function f_isChecked(rowdata)    {            return false;    }    function f_onCheckAllRow(checked)    {        for (var rowid in this.records)        {            if(checked)                addCheckedCustomer(this.records[rowid]['分机号码']);            else                removeCheckedCustomer(this.records[rowid]['分机号码']);        }    }    var checkedCustomer = [];    function findCheckedCustomer(CustomerID)    {
        for(var i =0;i<checkedCustomer.length;i++)        {            if(checkedCustomer[i] == CustomerID) return i;        }        return -1;    }        function addCheckedCustomer(CustomerID)    {        if(findCheckedCustomer(CustomerID) == -1)            checkedCustomer.push(CustomerID);    }
    function removeCheckedCustomer(CustomerID)    {        var i = findCheckedCustomer(CustomerID);        if(i==-1) return;        checkedCustomer.splice(i,1);    }    function f_onCheckRow(checked, data)    {        if (checked)        {          addCheckedCustomer(data.分机号码);        }        else         {removeCheckedCustomer(data.分机号码);        }    }    function newclick(item, i) {
        window.location.href = "/Manage/ExtensionEdit?group=@Model.GroupID";
        window.location.href=path;
    }
    function modifyclick(item, i) {
        var path = "/Manage/ExtensionEdit?groupID=@Model.GroupID&id="+actionNodeID.data.分机号码;
        window.location.href=path;
    }    function deleteclick(item, i) {
        del('@Model.GroupID',actionNodeID.data.分机号码);
    }
    $(document).ready(function () {
        $("#btnNew").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/ExtensionEdit?group=@Model.GroupID";
            }
        });
        $("#btnModify").ligerButton(
        {
            click: function () {
                var row = grid.getSelectedRow();
                if(row != null)
                {
                    var path = "/Manage/ExtensionEdit?groupID=@Model.GroupID&id="+row.分机号码;
                    window.location.href=path;
                }
            }
        });

        $("#btnDelete").ligerButton(
        {
            click: function () {
                delb('@Model.GroupID');
            }
        });
        $("#btnSort").ligerButton(
        {
            click: function () {
                window.location.href = "/Manage/ExtensionSort?id=@Model.GroupID";
            }
        });
        $("#btnMotion").ligerButton(
        {
            click: function () {
                motion('@Model.GroupID');
            }
        });
    });
</script>
<div id="maingrid">
</div>
@*@{
    var grid = new WebGrid(source: Model.ExtensionList, canPage: false);
}
<table>
    <tr>
        <th>
            选择
        </th>
        <th>
            分机号码
        </th>
        <th>
            分组
        </th>
        <th>
            用户名
        </th>
        <th>
            收费等级
        </th>
        <th>
            费率
        </th>
        <th>
            收费话类
        </th>
        <th>
        </th>
        <th>
        </th>
        <th>
        </th>
    </tr>
    @{
        foreach (var detail in Model.ExtensionList)
        {
        <tr class="ext E-@detail.收费等级">
            <td>@Html.CheckBox("选择", true, new { id = @detail.分机号码, @class = "account" })
            </td>
            <td>@detail.分机号码
            </td>
            <td>@detail.分组
            </td>
            <td>@detail.用户名
            </td>
            <td>@detail.收费等级
            </td>
            <td>@detail.费率
            </td>
            <td>@detail.收费话类
            </td>
            <td>@Html.ActionLink("修改", "ExtensionEdit", new { id = detail.分机号码, groupID = Model.GroupID })
            </td>
            <td>@Html.ActionLink("迁移", "ExtensionMotion", new { selectedItem = detail.分机号码, groupID = Model.GroupID })
            </td>
            <td>@Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", Model.GroupID, detail.分机号码))
            </td>
        </tr>
        }
    }
</table>*@ @*
@grid.GetHtml(
    alternatingRowStyle: "bg",
    columns: grid.Columns
    (
        grid.Column(format: (item) => Html.CheckBox("选择", true, new { id = item.分机号码, @class = "account" })),
        grid.Column("分机号码", "分机号码"),
        grid.Column("用户名", "用户名"),
        grid.Column("地址", "地址"),
        grid.Column("收费等级", "收费等级"),
        grid.Column("费率", "费率"),
        grid.Column("收费话类", "收费话类"),
        grid.Column("月杂费", "月杂费"),
        grid.Column("安装日期", "安装日期"),
        grid.Column(format: (item) => Html.ActionLink("修改", "ExtensionEdit", new { id = item.分机号码, groupID = Model.GroupID })),
        grid.Column(format: (item) => Html.ActionLink("迁移", "ExtensionMotion", new { selectedItem = item.分机号码})),
        grid.Column(format: (item) => Html.Raw(string.Format("<a href='javascript:' onclick=\"del('{0}','{1}')\">删除</a>", Model.GroupID , item.分机号码)))
    )
)*@ 